{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "50\n",
      "[93.0, 114.745174, '', '', 30.536718, '', '']\n"
     ]
    }
   ],
   "source": [
    "import xlrd\n",
    "\n",
    "doc = xlrd.open_workbook('./湖北/湖北_鄂州公司_无_35kV_楚胡线.xls')\n",
    "ws = doc.sheet_by_index(0)\t# 通过索引打开 指定的worksheet\n",
    "# ws1 = doc.sheet_by_name('湖北')\t# 通过表的名称打开指定的 worksheet\n",
    "# print(ws,ws1)\n",
    "# print(ws.nrows)  # 获取总行数\n",
    "\n",
    "# for i in ws.get_rows(): #获取表的迭代对象，for 循环时一行时一行数据\n",
    "    # print(i)\n",
    " \n",
    "\n",
    "# for i in list(ws.get_rows())[1:]: # 列表获取\n",
    "#     print(i)\n",
    "\n",
    " \n",
    "# print(ws.row(1))         # 获取第x行数据\n",
    "\n",
    "# print(ws.row_slice(1,0,3)) #获取一行 并切片\n",
    "\n",
    "# print(ws.row_types(1))   #获取一行\n",
    "\n",
    "print(ws.row_values(1))   #获取一行中所有的值\n",
    "\n",
    "# print(ws.row_len(1))  # 获取一行有几个字段\n",
    "\n",
    "# for i in range(0,ws.nrows):\n",
    "#     print(ws.row_values(i))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "行操作\n",
    "\n",
    "table = xlrd.open_workbook('./湖北/湖北_鄂州公司_无_35kV_楚胡线.xls')\n",
    "\n",
    "nrows = table.nrows  #获取该sheet中的有效行数\n",
    "\n",
    "table.row(rowx)  #返回由该行中所有的单元格对象组成的列表（可以指定列索引）\n",
    "\n",
    "table.row_slice(rowx,start_col,end_col)  #返回由该列中所有的单元格对象组成的列表\n",
    "\n",
    "table.row_types(rowx, start_colx=0, end_colx=None)    #返回由该行中所有单元格的数据类型组成的列表\n",
    "\n",
    "table.row_values(rowx, start_colx=0, end_colx=None)   #返回由该行中所有单元格的数据组成的列表\n",
    "\n",
    "table.row_len(rowx) #返回该列的有效单元格长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n",
      "[number:93.0, number:94.0]\n",
      "[2, 2]\n",
      "[114.745174, 114.745667]\n"
     ]
    }
   ],
   "source": [
    "import xlrd\n",
    "doc = xlrd.open_workbook('./湖北/湖北_鄂州公司_无_35kV_楚胡线.xls')\n",
    "table = doc.sheet_by_index(0)\n",
    "print(table.ncols)  # 获取总列数\n",
    "\n",
    "# print(table.col(0))  # 获取第几列数据\n",
    "\n",
    "print(table.col_slice(0,1,3))  # 获取第几列，并按索引划分\n",
    "\n",
    "print(table.col_types(0,1,3))\n",
    "\n",
    "print(table.col_values(1,1,3))   #获取一列中所有的值\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "列操作\n",
    "\n",
    "ncols = table.ncols   #获取列表的有效列数\n",
    "\n",
    "table.col(colx, start_rowx=0, end_rowx=None)  #返回由该列中所有的单元格对象组成的列表\n",
    "\n",
    "table.col_slice(colx, start_rowx=0, end_rowx=None)  #返回由该列中所有的单元格对象组成的列表\n",
    "\n",
    "table.col_types(colx, start_rowx=0, end_rowx=None)    #返回由该列中所有单元格的数据类型组成的列表\n",
    "\n",
    "table.col_values(colx, start_rowx=0, end_rowx=None)   #返回由该列中所有单元格的数据组成的列表\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import xlrd\n",
    "doc = xlrd.open_workbook('./湖北/湖北_鄂州公司_无_35kV_楚胡线.xls')\n",
    "table = doc.sheet_by_index(0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "table.cell(rowx,colx)   #返回单元格对象\n",
    "\n",
    "table.cell_type(rowx,colx)    #返回单元格中的数据类型\n",
    "\n",
    "table.cell_value(rowx,colx)   #返回单元格中的数据\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "3cb250e525bdc45e0c81f60515e2b301d41451e11e00718716680ec78afef40b"
  },
  "kernelspec": {
   "display_name": "Python 3.8.8rc1 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8rc1"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
